home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / gimp-2.0.5-i586-setup / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / addborder.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2004-09-26  |  5.3 KB  |  175 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ; Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
  16. ;
  17. ; Version 0.2 10.6.97 Changed to new script-fu interface in 0.99.10
  18.  
  19. ; Delta the colour by the given amount. Check for boundary conditions
  20. ; If < 0 set to zero 
  21. ; If > 255 set to 255
  22. ; Return the new value
  23.  
  24. (define (deltacolour col delta)
  25.   (let* ((newcol (+ col delta)))
  26.     (if (< newcol 0) (set! newcol 0))
  27.     (if (> newcol 255) (set! newcol 255))
  28.     newcol)
  29.   )
  30.  
  31. (define (adjcolour col delta)
  32.   (mapcar (lambda (x) (deltacolour x delta)) col)
  33. )
  34.  
  35. (define (gen_top_array xsize ysize owidth oheight width height)
  36.   (let* ((n_array (cons-array 10 'double)))
  37.     (aset n_array 0 0 )
  38.     (aset n_array 1 0 )
  39.     (aset n_array 2 xsize)
  40.     (aset n_array 3 ysize)
  41.     (aset n_array 4 (+ xsize owidth))
  42.     (aset n_array 5 ysize)
  43.     (aset n_array 6 width)
  44.     (aset n_array 7 0 )
  45.     (aset n_array 8 0 )
  46.     (aset n_array 9 0 )
  47.     n_array)
  48. )
  49.  
  50. (define (gen_left_array xsize ysize owidth oheight width height)
  51.   (let* ((n_array (cons-array 10 'double)))
  52.     (aset n_array 0 0 )
  53.     (aset n_array 1 0 )
  54.     (aset n_array 2 xsize)
  55.     (aset n_array 3 ysize)
  56.     (aset n_array 4 xsize)
  57.     (aset n_array 5 (+ ysize oheight))
  58.     (aset n_array 6 0 )
  59.     (aset n_array 7 height )
  60.     (aset n_array 8 0 )
  61.     (aset n_array 9 0 )
  62.     n_array)
  63. )
  64.  
  65. (define (gen_right_array xsize ysize owidth oheight width height)
  66.   (let* ((n_array (cons-array 10 'double)))
  67.     (aset n_array 0 width )
  68.     (aset n_array 1 0 )
  69.     (aset n_array 2 (+ xsize owidth))
  70.     (aset n_array 3 ysize)
  71.     (aset n_array 4 (+ xsize owidth))
  72.     (aset n_array 5 (+ ysize oheight))
  73.     (aset n_array 6 width)
  74.     (aset n_array 7 height)
  75.     (aset n_array 8 width )
  76.     (aset n_array 9 0 )
  77.     n_array)
  78. )
  79.  
  80. (define (gen_bottom_array xsize ysize owidth oheight width height)
  81.   (let* ((n_array (cons-array 10 'double)))
  82.     (aset n_array 0 0 )
  83.     (aset n_array 1 height)
  84.     (aset n_array 2 xsize)
  85.     (aset n_array 3 (+ ysize oheight))
  86.     (aset n_array 4 (+ xsize owidth))
  87.     (aset n_array 5 (+ ysize oheight))
  88.     (aset n_array 6 width)
  89.     (aset n_array 7 height)
  90.     (aset n_array 8 0 )
  91.     (aset n_array 9 height)
  92.     n_array)
  93. )
  94.  
  95. (define (script-fu-addborder aimg adraw xsize ysize colour dvalue)
  96.   (let* ((img (car (gimp-drawable-get-image adraw)))
  97.      (owidth (car (gimp-image-width img)))
  98.      (oheight (car (gimp-image-height img)))
  99.      (old-fg (car (gimp-palette-get-foreground)))
  100.          (old-bg (car (gimp-palette-get-background)))
  101.      (width (+ owidth (* 2 xsize)))
  102.      (height (+ oheight (* 2 ysize)))
  103.      (layer (car (gimp-layer-new img width height RGBA-IMAGE "Border-Layer" 100 NORMAL-MODE))))
  104. ;Add this for debugging    (verbose 4)
  105.     (gimp-image-undo-group-start img)
  106.     (gimp-drawable-fill layer TRANSPARENT-FILL)
  107.     (gimp-image-resize img
  108.                width
  109.                    height
  110.                    xsize
  111.                    ysize)
  112.     (gimp-palette-set-background (adjcolour colour dvalue))
  113.     (gimp-free-select img
  114.               10
  115.               (gen_top_array xsize ysize owidth oheight width height)
  116.               CHANNEL-OP-REPLACE
  117.               0
  118.               0
  119.               0.0)
  120.     (gimp-edit-fill layer BACKGROUND-FILL)
  121.     (gimp-palette-set-background (adjcolour colour (/ dvalue 2)))
  122.     (gimp-free-select img
  123.               10
  124.               (gen_left_array xsize ysize owidth oheight width height)
  125.               CHANNEL-OP-REPLACE
  126.               0
  127.               0
  128.               0.0)
  129.     (gimp-edit-fill layer BACKGROUND-FILL)
  130.     (gimp-palette-set-background (adjcolour colour (- 0 (/ dvalue 2))))
  131.     (gimp-free-select img
  132.               10
  133.               (gen_right_array xsize ysize owidth oheight width height)
  134.               CHANNEL-OP-REPLACE
  135.               0
  136.               0
  137.               0.0)
  138.  
  139.     (gimp-edit-fill layer BACKGROUND-FILL)
  140.     (gimp-palette-set-background (adjcolour colour (- 0 dvalue)))
  141.     (gimp-free-select img
  142.               10
  143.               (gen_bottom_array xsize ysize owidth oheight width height)
  144.               CHANNEL-OP-REPLACE
  145.               0
  146.               0
  147.               0.0)
  148.  
  149.     (gimp-edit-fill layer BACKGROUND-FILL)
  150.     (gimp-selection-none img)
  151.     (gimp-image-add-layer img layer 0)
  152.     (gimp-image-undo-group-end img)
  153.     (gimp-palette-set-background old-bg)
  154.     (gimp-displays-flush)
  155.     )
  156. )
  157.  
  158. (script-fu-register "script-fu-addborder"
  159.             _"<Image>/Script-Fu/Decor/Add _Border..."
  160.             "Add a border around an image"
  161.             "Andy Thomas <alt@picnic.demon.co.uk>"
  162.             "Andy Thomas"
  163.             "6/10/97"
  164.             "RGB*"
  165.             SF-IMAGE "Input Image" 0
  166.             SF-DRAWABLE "Input Drawable" 0
  167.             SF-ADJUSTMENT _"Border X Size" '(12 1 250 1 10 0 1)
  168.             SF-ADJUSTMENT _"Border Y Size" '(12 1 250 1 10 0 1)
  169.             SF-COLOR _"Border Color" '(38 31 207)
  170.             SF-ADJUSTMENT _"Delta Value on Color" '(25 1 255 1 10 0 1)
  171.             )
  172.